package com.glx.test.controller;

// ProblemController.java
import com.glx.test.pojo.Problem;
import com.glx.test.pojo.Submission;
import com.glx.test.pojo.TestCase;
import com.glx.test.response.ListResponse;
import com.glx.test.response.ProblemResponse;
import com.glx.test.response.SubmissionResponse;
import com.glx.test.response.SubmissionWithProblemResponse;
import com.glx.test.service.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/problems")
public class ProblemController {
    @Autowired
    private ProblemService problemService;



    @PostMapping("/create")
    public ProblemResponse createProblem(@RequestBody Problem problem) {
        return problemService.createProblem(problem);
    }

    @PostMapping("/insertTestCase")
    public ProblemResponse insertTestCase(@RequestBody TestCase testCase) {
        return problemService.insertTestCase(testCase);
    }

    @GetMapping("/searchFullProblems")
    public ListResponse searchFullProblems(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                           @RequestParam(value = "pageSize", defaultValue = "10") int j) {
        return problemService.SearchFullProblems(pageNum, j);
    }

    @GetMapping("/getProblemById/{id}")
    public ProblemResponse getProblemById(@PathVariable Long id) {
        return problemService.getProblemById(id);
    }

    @GetMapping("/getSubmissionByUserId/{user_id}")
    public SubmissionWithProblemResponse getSubmissionByUserId(@PathVariable Long user_id) {
        return problemService.getSubmissionByUserId(user_id);
    }

    @GetMapping("/getSubmissionByProblemId/{problem_id}")
    public SubmissionResponse getSubmissionByProblemId(@PathVariable Long problem_id){
        return problemService.getSubmissionByProblemId(problem_id);
    }

    @PostMapping("/insertSubmission")
    public SubmissionResponse insertSubmission(@RequestBody Submission submission) {
        return problemService.insertSubmission(submission);
    }
}